package backtrackAlgorithm;

import java.util.ArrayList;
import java.util.List;

/*
 *@description 组合
 *@author hkfan
 *@version 1.0
 *@create 2025/6/16 15:36
 */
public class LeetCode_77 {

    public List<List<Integer>> combine(int n, int k) {
        ArrayList<List<Integer>> lists = new ArrayList<>();
        solution(n,k,lists,new ArrayList<Integer>(),1,1);
        return lists;
    }

    private void solution(int n, int k, List<List<Integer>> lists, List<Integer> list, int i, int index) {
        if (index==k && list.size()==k){
            lists.add(new ArrayList<>(list));
            return;
        }
        if (i>n){
            return;
        }
        for (; i <= n; i++) {
            list.add(i);
            solution(n,k,lists,list,i+1,index+1);
            list.remove(lists.size()-1);
        }
    }


}
